package top.lshaci.learning.springboot.web.fastjson.writer;

import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.writer.ObjectWriter;

import java.lang.reflect.Type;
import java.time.Year;

/**
 * ObjectWriterYear
 *
 * @author liangxu
 */
public class ObjectWriterYear implements ObjectWriter<Year> {

    public static final ObjectWriterYear INSTANCE = new ObjectWriterYear();

    @Override
    public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
        if (object == null) {
            jsonWriter.writeNull();
            return;
        }

        Year year = (Year) object;
        jsonWriter.writeInt32(year.getValue());
    }
}
